import * as DevTeamAction from 'actions/dev-team';
import { getFetchStatus } from 'actions/util';
import * as React from 'react';
import * as ReactRedux from 'react-redux';
import { Select } from 'antd';

const { Option } = Select

const mapStateToProps = (state) => {
  return {
    placeholder: '选择所管理的开发组',
    optionFilterProp: "children",
    notFoundContent: "无法找到",
    searchPlaceholder: "输入关键词",
    showSearch: true,
    isFetching: getFetchStatus(state, DevTeamAction.managedDevTeam),
    options: state.managedDevTeam.map(team => {
      return {
        value: team.id,
        text: team.name
      };
    }),
  }
};

const mapDispatchToProps = (dispatch) => {
  return {
    initSelectionData: () => {
      return dispatch(DevTeamAction.managedDevTeam());
    }
  };
};

class ManagedDevTeamSelection extends React.Component {
  componentDidMount() {
    this.props.initSelectionData();
  }

  render() {
    return (
      <Select {...this.props}>
        {this.props.options.map(({ value, text }) =>
          <Option key={value}>{text}</Option>
        )}
      </Select>
    )
  }
}

export default ReactRedux.connect(mapStateToProps, mapDispatchToProps)(ManagedDevTeamSelection);
